import request from '../utils/request';
import type { ApiResponse, CaptchaResponse, LoginResponse, RefreshTokenResponse } from '../types/api';

// 发送验证码
// 导出一个异步函数sendVerificationCode，用于发送验证码
export const sendVerificationCode = async (phone: string): Promise<ApiResponse<CaptchaResponse>> => {
  // 发送POST请求，请求地址为'/api/send-code'，参数为phone
  const response = await request.post<ApiResponse<CaptchaResponse>>('/api/send-code', { phone });
  // 返回响应数据
  return response.data;
};

// 手机号登录
export const loginWithPhone = async (phone: string, code: string): Promise<ApiResponse<LoginResponse>> => {
  const response = await request.post<ApiResponse<LoginResponse>>('/api/login', { phone, code });
  return response.data;
};

// 刷新 token
export const refreshToken = async (refreshToken: string): Promise<ApiResponse<RefreshTokenResponse>> => {
  const response = await request.post<ApiResponse<RefreshTokenResponse>>('/api/refresh-token', { refreshToken });
  return response.data;
}; 